package com.dc.ai.controller;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.dc.ai.common.result.Result;
import com.dc.ai.entity.dto.LoginDTO;
import com.dc.ai.entity.po.LoginResult;
import com.dc.ai.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Tag(name = "认证中心")
@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
@Slf4j
public class AuthController {

    private final AuthService authService;

    @Operation(summary = "账号登录", description = "账号登录")
    @PostMapping("/login")
    public Result<LoginResult> login(@Validated @RequestBody LoginDTO loginDto) {
        LoginResult loginResult = authService.login(loginDto.getUsername(), loginDto.getPassword());
        return Result.success(loginResult);
    }


    @Operation(summary = "退出登录")
    @PostMapping("/logout")
    public Result logout() {
        authService.logout();
        return Result.success();
    }

}
